<template>
  <div class="personal">
    <img class="topimg" src="../../assets/img/p-bg.png" alt="">
    <div class="info-box">
      <img src="../../assets/img/tx.png" alt="">
      <div style="margin-top: 8px">{{userInfo.name || '用户未登录'}}</div>
    </div>
    <div class="optionlist">
<!--      <div class="options" @click="gotoNext('/staging?openid=' + $route.query.openid)">-->
<!--        <img class="options-icon" src="../../assets/icon/icon1.png" alt="">-->
<!--        <span class="options-title">我的草稿</span>-->
<!--        <img class="options-go" src="../../assets/img/jt.png" alt="">-->
<!--      </div>-->
<!--      <div class="options" @click="gotoNext('/integral?openid=' + $route.query.openid)">-->
<!--        <img class="options-icon" src="../../assets/icon/icon2.png" alt="">-->
<!--        <span class="options-title">我的消息</span>-->
<!--        <img class="options-go" src="../../assets/img/jt.png" alt="">-->
<!--      </div>-->
      <div class="options" @click="gotoUnbind">
        <img class="options-icon" src="../../assets/icon/icon3.png" alt="">
        <span class="options-title">{{userInfo.name?'解除绑定':'用户绑定'}}</span>
        <img class="options-go" src="../../assets/img/jt.png" alt="">
      </div>
    </div>
    <van-button class="publish_btn" @click="closeview" block type="primary" round>退出登录</van-button>

    <confirm-dialog v-model="showDia" @ok="handleOk"/>
  </div>
</template>

<script>
import {Toast} from 'vant'
import GHeader from '../../components/Header.vue'
import {getuserinfo, deleteuserinfo} from '@/api/myapi'
import ConfirmDialog from "@/components/confirmDialog.vue";
export default {
  name: 'Personal',
  components: {
    ConfirmDialog,
    GHeader
  },
  data() {
    return {
      form: {},
      userInfo: {},
      show: false,
      showBottom: false,
      chooseObj: {
        haschoose: []
      },
      departList: [],
      defaultShowList: [],
      showDia: false
    }
  },
  methods: {
    closeview() {
      try {
        //这个可以关闭安卓系统的手机
        document.addEventListener('WeixinJSBridgeReady', function(){ WeixinJSBridge.call('closeWindow')}, false)
      } catch (error) {
      }
      try {
        //这个可以关闭ios系统的手机
        WeixinJSBridge.call('closeWindow')
      } catch (error) {
      }
    },
    getuserinfo() {
      getuserinfo(this.$route.query.openid, res=> {
        if(res.code === 0) {
          this.userInfo = res.data || {}
        } else {
          this.userInfo = {}
        }
      })
    },
    gotoUnbind() {
      if(this.userInfo.name) {
        this.showDia = true
      } else {
        // Toast('您没有绑定用户')
        setTimeout(() => {
          this.$router.replace('/register?openid=' + this.$route.query.openid)
        }, 200)
      }
    },
    handleOk() {
      deleteuserinfo(this.userInfo.id, res => {
        if(res.code === 0) {
          Toast('解绑成功')
          this.getuserinfo()
          setTimeout(() => {
            this.$router.replace('/register?openid=' + this.$route.query.openid)
          }, 200)
        } else {
          Toast(res.msg)
        }
      })
    },
    gotoNext(path) {
      return
      this.$router.push(path)
    }
  },
  async mounted() {
    this.getuserinfo()
  }
}
</script>
<style lang="less" scoped>
@import '../../assets/style/themeVariable.less';
.personal {
  padding: 0;
  position: relative;
  .personal-header {
    padding-top: 6px;
    color: #fff;
  }
  .topimg {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    min-height: 255px;
    z-index: 101;
  }
  .info-box {
    position: absolute;
    background: transparent;
    margin: 0px auto 20px auto;
    border-radius: 6px;
    width: 100%;
    padding: 0px 30px 0px 30px;
    box-sizing: border-box;
    text-align: center;
    top: 50px;
    z-index: 102;
    img {
      width: 76px;
      height: 76px;
      border-radius: 50%;
      vertical-align: middle;
    }
    div {
      font-size: 16px;
      color: #FFFFFF;
    }
    span {
      padding-left: 10px;
    }
    .depart {
      background: rgba(255, 255, 255, 0.3);
      display: inline-block;
      padding: 6px 10px;
      font-size: 13px;
      border-radius: 15px;
      img {
        width: 15px;
        vertical-align: middle;
        height: 15px;
        border-radius: 0;
        margin-right: 3px;
        margin-top: -2px;
      }
    }
  }
  .optionlist {
    position: relative;
    background: rgba(255, 255, 255, 0.2);
    //backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    backdrop-filter: blur(25px);
    box-shadow: 0px 2px 37px rgba(0, 0, 0, 0.14);
    //background: url('../../assets/img/mb.png');
    //background-size: 100% 100%;
    width: 90%;
    margin: -50px auto 0 auto;
    padding: 10px 24px 10px 24px;
    box-sizing: border-box;
    border-radius: 10px;
    z-index: 101;
    .options {
      display: flex;
      align-items: center;
      padding: 14px 0px;
      border-bottom: 1px solid rgba(221, 221, 221, 0.6);
      background: transparent;
      &-icon {
        width: 26px;
        height: auto;
        padding-right: 14px;
      }
      &-go {
        width: 6px;
        height: auto;
      }
      span {
        flex: 1;
        color: #000000;
      }
    }
  }
  .publish_btn {
    background: linear-gradient(168.4deg, #7AD7FF 0%, #347BF1 100%);
    //box-shadow: 0px 8.5px 25.5px  #E9EFF5;
    border: none;
    width: 90%;
    margin: 30px auto;
  }
}
.optionarea {
  font-size: 15px;
  display: flex;
  padding: 15px;
  div {
    flex: 1;
    &:last-child {
      text-align: right;
    }
  }
}
.depart_list {
  height: 320px;
  overflow: auto;
  display: flex;
  align-items: center;
  flex-direction: column;
  .depart_list_item {
    font-size: 15px;
    padding: 10px;
    border-bottom: 1px solid #dddddd;
  }
  .choose {
    color: #2A83EF;
  }
}
</style>
